const relationSchema = {
  0: [1, 2],
  1: [3, 4],
  2: [5, 6],
  5: [7, 8],
  6: [9, 10],
  9: [11],
  11: [12],
  12: [13],
};
// 深度遍历 DFS
function deepIterator(data) {
  return getDeep(data, 0);
}
function getDeep(data, key) {
  if (!data[key]) return 0;
  return Math.max(getDeep(data, data[key][0]), getDeep(data, data[key][1])) + 1;
}
// console.log(deepIterator(relationSchema));

// 广度遍历 BFS
function PrintFromTopToBottom(obj) {
  const queues = [0];
  while (queues.length > 0) {
    const firstC = queues.shift();
    console.log(firstC);
    if (obj[firstC] && obj[firstC].length > 0) {
      queues.push(...obj[firstC]);
    }
  }
}
// PrintFromTopToBottom(relationSchema);

const arr = [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1];
var hasPathSum = function (root, targetSum) {
  let aaa = false
  function foo(index, count) {
    if (root[index * 2 + 1]) {
      if (count + root[index * 2 + 1] === targetSum) {
        aaa = true;
      } else {
        foo(index * 2 + 1, count + root[index * 2 + 1]);
      }
    }
    if (root[index * 2 + 2]) {
      if (count + root[index * 2 + 2] === targetSum) {
        aaa = true;
      } else {
        foo(index * 2 + 2, count + root[index * 2 + 2]);
      }
    }
  }
  foo(0, root[0])
  return aaa;
};
console.log(hasPathSum(arr, 22));
